package com.dq.domain.orders;

import com.dq.vo.baseVo.VO;
import com.dq.domain.orders.info.OrderInfo;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/11/20 0020 17:17:50
 */
@Data
@Entity
@ApiModel("缺货单")
public class ShortageOrder extends Orders implements VO.ToVO {

    @ApiModelProperty("关联采购单/销售单")
    @ManyToOne
    public Orders relateOrder;

//    @ApiModelProperty("金额, 放到 orders 中")
//    protected BigDecimal price;

    @ApiModelProperty("缺货单状态")
    @Enumerated(EnumType.ORDINAL)
    public ShortageStatus shortageStatus;
    @ApiModelProperty("缺货单关联订单类型")
    @Enumerated(EnumType.ORDINAL)
    public ShortageType shortageType;

    @ApiModelProperty("商品件数")
    protected Long payGoodsNum;
    @ApiModelProperty("分类数")
    protected Long cateNum;

    public enum ShortageStatus{
        notReplenish("未补货"),
        alreadyReplenish("已补货");

        public String name;

        ShortageStatus(String name){
            this.name = name;
        }
    }
    public enum ShortageType{
        all("all"),
        userOrder("销售单"),
        orgOrder("采购单");

        public String name;

        ShortageType(String name){
            this.name = name;
        }
    }



    @Data
    @ApiModel("缺货订单视图")
    public static class Vo implements VO {

    }

    @Data
    @ApiModel("缺货订单列表视图")
    public static class ShortageOrderListVo{
        @ApiModelProperty("缺货单id")
        protected Long id;
        @ApiModelProperty("缺货单号")
        protected String shortageOrderNo;
        @ApiModelProperty("采购/销售单号")
        protected String orgOrderNo;
        @ApiModelProperty("采购/销售单日期")
        protected String orgOrderTime;
        @ApiModelProperty("缺货单生成日期")
        protected String shortageGenerateTime;
        @ApiModelProperty("采购/销售单总价")
        protected BigDecimal orgAmount;
        @ApiModelProperty("缺货单总价")
        protected BigDecimal shortageAmount;

        @ApiModelProperty("门店")
        protected Long orgId;
        @ApiModelProperty("门店")
        protected String orgName;

        @ApiModelProperty("商品件数")
        protected Long payGoodsNum;
        @ApiModelProperty("分类数")
        protected Long cateNum;

        @ApiModelProperty("缺货单状态")
        public String shortageStatusEn;
        @ApiModelProperty("缺货单状态")
        public String shortageStatusCn;
        @ApiModelProperty("缺货单关联订单类型")
        public String shortageTypeEn;
        @ApiModelProperty("缺货单关联订单类型")
        public String shortageTypeCn;

        @ApiModelProperty("订单详情")
        protected List<OrderInfo.OrgOrderInfoVo> orgOrderInfoVos;
    }

    public ShortageOrderListVo toShortageOrderListVo(){
        ShortageOrder.ShortageOrderListVo shortageOrderListVo = new ShortageOrder.ShortageOrderListVo();
        shortageOrderListVo.id = this.getId();
        shortageOrderListVo.shortageOrderNo = fmt(this.getOrdersNo());
        shortageOrderListVo.orgOrderNo = this.getRelateOrder() != null ? fmt(this.getRelateOrder().getOrdersNo()):"";
        shortageOrderListVo.orgOrderTime =this.getRelateOrder() != null ? fmt(this.getRelateOrder().getCreateTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS):"";
        shortageOrderListVo.shortageGenerateTime = fmt(this.getCreateTime(),TimeUtil.YYYY_MM_DD_HH_MM_SS);
        shortageOrderListVo.orgAmount =this.getRelateOrder() != null ?  fmt(this.getRelateOrder().getPrice()):null;
        shortageOrderListVo.shortageAmount = fmt(this.getPrice());

        shortageOrderListVo.orgId = this.getOrg().getId();
        shortageOrderListVo.orgName = this.getOrg().getSimpleName();

        shortageOrderListVo.payGoodsNum = fmt(this.getPayGoodsNum());
        shortageOrderListVo.cateNum = fmt(this.getCateNum());

        shortageOrderListVo.shortageStatusEn = fmt(this.getShortageStatus().toString());
        shortageOrderListVo.shortageStatusCn = fmt(this.getShortageStatus().name);
        shortageOrderListVo.shortageTypeEn =this.getShortageType()!= null? fmt(this.getShortageType().toString()):"";
        shortageOrderListVo.shortageTypeCn = this.getShortageType()!= null? fmt(this.getShortageType().name):"";

        return shortageOrderListVo;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();

        return vo;
    }
}
